/**
 * 1.本代码为云笔记web端开发小组共同拥有。
 * 2.组内成员有 聂道鑫、徐斌强、何瑞、钟倩。
 * 3.联系方式：442342707@qq.com
 */
package com.yunbiji.controller;

import java.util.List;

import org.apache.log4j.Logger;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.yunbiji.interceptor.SessionInterceptor;
import com.yunbiji.model.Notes;

@Before(SessionInterceptor.class)
/**
 *笔记本列表类
 * @author 聂道鑫
 *
 */
public class EditorController extends Controller
{
	private static final Logger logger = Logger.getLogger(EditorController.class);
	
	public void index()
	{
		render("welcome.html");
	}
/**
 * 取得笔记本内容
 */
	public void getContent()
	{

		try
		{
			logger.info("getContent方法开始了");
			int id = getSessionAttr("id");
			String tel = getSessionAttr("username");
			String content = getPara("content");
			
			Notes.dao.getContent(content, id, tel);
			String text = Notes.dao.queryStrContent(id, tel);
			setAttr("content", text);
			
			String noteName=Notes.dao.queryStrName(id, tel);
			setAttr("noteNameAboveEditor", noteName);
			
			// 确认详细结果分页
			String pId = getSessionAttr("pId");
			Integer pageno = getSessionAttr("pageno");
			List<Notes> list = Notes.dao.getNotes(tel, pId, pageno);
			setAttr("pageno", pageno);
			setAttr("getNotes_Notes", list);
			render("welcome.html");	
			logger.info("getContent方法结束了");
		}
		catch(NullPointerException e)
		{
			logger.error("getContent出现异常");
			setAttr("alertInfo", "新建笔记之前请先选中笔记本或者新建笔记本");
			render("errors/alert.html");
			getResponse().setHeader("Refresh", "2;URL=index");
		}


	}
}
